<?php
class Malbumdetail extends CI_Model{
	function __construct(){
		parent::__construct();
	}
	
	function loadAlbumDetails($albumid){
		$sql = "select * 
				from tbalbumdetail
				where albumid=? and status = 1
				order by id ";
		
		$query = $this->db->query($sql,array("$albumid"));
		return $query->result();
	}
	function getCount($albumid,$status){
		$sql = "select count(1) num
				from tbalbumdetail
				where albumid = ? and status = ?";
		$query = $this->db->query($sql,array("$albumid","$status"));
		foreach ($query->result() as $row){
			return $row->num;
		}
		return 0;
	}
	function saveAlbumDetail($albumid,$url){
		$sql = "insert into tbalbumdetail(albumid,url,createtime,status) values(?,?,now(),0)";
		$query = $this->db->query($sql,array("$albumid","$url"));
		return $this->db->affected_rows();
	}
	function delAblumDetails($id){
	
		$sql = "update tbalbumdetail
				set status = 0
				where id = ?";
		$this->db->query($sql,array("$id"));
	
	}
	function deleteByAlbumid($albumid){
		$sql = "update tbalbumdetail
				set status = 0
				where albumid = ?";
		$this->db->query($sql,array("$albumid"));
	}
	function loadAlbumDetailsDeleted($uid){
		$sql = "select ad.*
				from tbalbumdetail ad
				join tbAlbum a on a.id = ad.albumid
				where a.uid = ? and ad.status = 0 and a.status!=0";
		$query = $this->db->query($sql,array("$uid"));
		return $query->result();
	}
	function restoreAblumDetail($id){
		$sql = " update tbalbumdetail
				set  status = 1
				where id = ? ";
		$this->db->query($sql,array("$id"));
	}
	function deleteAlbumDetailDeep($id){
		$sql = " delete from tbalbumdetail
				where id = ? ";
		$this->db->query($sql,array("$id"));
	}
}
?>